
from lib.api import *
import re


def suite_setup():
    INFO('返回token')
    response = requests.post("http://******************/api/v1/auth/userToken",
                             json={"userAccount": "******************", "password": "******************"}
                             )
    global auth_token
    auth_token = str(response.json()["data"]["token"])



class API_2038:
    name = 'API_2038'       # 测试用例名字
    def teststeps(self):

        INFO('数据点监控接口：获取所有子系统接口 测试     #2.6')
        INFO('前置条件：token 正确')
        response = requests.post("http://******************/api/v1/dataManagement/getSubAppList",
                                 headers={
                                     "auth-token": auth_token
                                 }
                                 )
        expectedResult='''
{
    "status": "success", 
    "msg": "查询成功", 
    "code": 0, 
    "type": null, 
    "data": [
        {
            "id": 106, 
            "subAppName": "ACS", 
            "subAppDesc": "门禁系统（ACS）"
        }, 
        {
            "id": 104, 
            "subAppName": "AFC", 
            "subAppDesc": "自动售检票系统（AFC）"
        }, 
        {
            "id": 102, 
            "subAppName": "BAS", 
            "subAppDesc": "环境与设备监控系统（BAS）"
        }
    ]
}
        '''
        outExpectedResult='预期结果:'+expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))





class API_2039:
    name = 'API_2039'       # 测试用例名字
    def teststeps(self):

        INFO('数据点监控接口：获取所有子系统接口 测试     #2.6')
        INFO('前置条件：token 过期')
        response = requests.post("http://******************/api/v1/dataManagement/getSubAppList",
                                 headers={
                                     "auth-token":'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlS2V5IjoiIiwidXNlck5hbWUiOiJ5enlhZG1pbiIsImV4cCI6MTYyMTkzNzIwNCwidXNlcklkIjoieXp5YWRtaW4ifQ.xVITR8Cn0zLrJSA3tKMt48bTyk6tFhlRwjIp4e_yFys'
                                 }
                                 )
        expectedResult='''
{
    "status": "false",
    "msg": "请求失败",
    "code": 1,
    "type": null,
    "data": 0
}
        '''
        outExpectedResult='预期结果:'+expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))





class API_2040:
    name = 'API_2040'       # 测试用例名字
    def teststeps(self):

        INFO('数据点监控接口：获取所有子系统接口 测试     #2.6')
        INFO('前置条件：token 为空')
        response = requests.post("http://******************/api/v1/dataManagement/getSubAppList",
                                 # headers={
                                 #     "auth-token":auth_token
                                 # }
                                 )
        expectedResult='''
{
    "status": "false",
    "msg": "请求失败",
    "code": 1,
    "type": null,
    "data": 0
}
        '''
        outExpectedResult='预期结果:'+expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))





